<template>
    <a-modal :title="$t('Rename')+' '+$t('Snap')" v-model='rename' @cancel='cancelhandle' width='35%' @ok='modisub' :cancelText="$t('Cancel')" :okText="$t('Sure')" :maskClosabel='false' v-dragModal>
        <a-spin size="large" style="position:absolute;left:50%; top:50%; transform: translate(-50%, -50%);z-index:1;background:rgba(255,255,255,.6);padding:10%" tip="Submit successfully Loading..." v-if="spinning == true"></a-spin>
        <a-form :form='form'>
            <a-form-item :label="$t('Snap')+$t('Name')" v-bind='formlayout'>
                <a-input v-decorator="['replica_name',{
                    rules:[{required:true,message:$t('Enter') + $t('Snap')+$t('Name')},
                           {pattern:namePattern,message:$t('Not_enter_special_characters')}],
                    initialValue:tarname ? tarname.name : ''
                }]" :placeholder="tarname ? tarname.name : '' "></a-input>
            </a-form-item>
        </a-form>
    </a-modal>
</template>
<script>
import request from '@/request/request'

export default {
    name:'copysnap',
    props:['rr','tarname'],
    data(){
        return{
            form:this.$form.createForm(this),
            rename:false,
            formlayout:{
                labelCol:{span:6},
                wrapperCol:{span:14}
            },
            spinning:false
        }
    },
    watch:{
        rr(val){
            this.rename=val
        }
    },
    methods:{
        cancelhandle(e){
            // this.rename=false
            this.$emit('omodal',false, true)
            this.form.resetFields();
            this.spinning=false
        },
        modisub(e){
            e.preventDefault();
            this.form.validateFields((err,value)=>{
                if(!err){
                    this.spinning = true
                    // this.$axios({
					// 	method: 'post',//原来是put
					// 	url: this.allurl+'block/snap/rename',//原来是block/snap
					// 	data: {
                    //         pool_id: this.tarname.pool_id,
                    //         image_id: this.tarname.image_id,
                    //         snapshot_id: this.tarname.id,
                    //         new_snapshot_name: value.replica_name,
                    //         old_snapshot_name: this.tarname.name,
                    //         pool_name: this.tarname.pool_name,
                    //         block_name: this.tarname.block_name,
                    //         // pool:this.tarname.pool_name,
	                //     	// block:this.tarname.block_name,
	                //     	// origin_name:this.tarname.name,
	                //     	// replica_name:value.replica_name
	                //     }
                    // })
                    request('post', 'block/snap/rename', {
                        pool_id: this.tarname.pool_id,
                        image_id: this.tarname.image_id,
                        snapshot_id: this.tarname.id,
                        new_snapshot_name: value.replica_name,
                        old_snapshot_name: this.tarname.name,
                        pool_name: this.tarname.pool_name,
                        block_name: this.tarname.block_name,
                    })
                    .then(res=>{
                        this.selectedRowKeys = [];
                        this.model(res.data.id) //返回模板
                        this.notice(res.data.id, res.data.params, res.data.flag) //通知列表显示
					    // this.gettask()  //任务栏信息
                        // this.rename=false
                        this.spinning = false
                        this.$emit('omodal',false, false)
						this.form.resetFields()  //重置弹窗
                    }).catch(err => {
                        this.selectedRowKeys = [];
                        this.spinning = false;
                        this.$emit('omodal',false, false);
						this.form.resetFields();  //重置弹窗
                    })
                }
            })
        }	
    }
}
</script>